﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            TreeNode root = new TreeNode();// 创建根节点
            root.Text = "根节点"; //节点文本
            root.Value = "0";//节点值
            for (int i = 0; i < 10; i++)
            {
                TreeNode node = new TreeNode();//创建子节点
                node.Text = "节点" + i.ToString();
                node.Value = i.ToString();
                TreeNode leaf = new TreeNode();
                leaf.Text = "节点0" + i.ToString() ;
                leaf.Value = "0" + i.ToString();
                node.ChildNodes.Add(leaf);//添加节点
                root.ChildNodes.Add(node);
            
            }
                TreeViewDemo.Nodes.Add(root);//添加节点
        
        }
    }
    protected void Collapse_Click(object sender, EventArgs e)
    {
        TreeViewDemo.CollapseAll();
    }
    protected void Expand_Click(object sender, EventArgs e)
    {
        TreeViewDemo.ExpandAll(); 
    }
    protected void CollNode_Click(object sender, EventArgs e)
    {
        try
        {
            if(NodePath.Text!=string.Empty)
            TreeViewDemo.FindNode(NodePath.Text).Collapse();
        }
        catch
        {
            Response.Write("没有找到对应节点");
        }
    }
}
